package com.four.reimbursemanage.dao;


import com.four.reimbursemanage.entity.Dailyapply;
import com.four.reimbursemanage.entity.EntertainApply;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * 日常报销申请Mapper接口
 * 
 * @author lwy
 * @date 2024-09-18
 */
@Mapper
public interface DailyapplyMapper 
{
    /**
     * 查询日常报销申请
     * 
     * @param id 日常报销申请主键
     * @return 日常报销申请
     */
    public Dailyapply selectDailyapplyById(Integer id);

    @Select("select * from dailyapply where id=#{id}")
    public  Dailyapply selectById(Integer id);
    /**
     * 查询日常报销申请列表
     * 
     *
     * @return 日常报销申请集合
     */
    @Select("<script>" +
            "SELECT * FROM dailyapply" +
            "<where>" +
            "    <if test=\"writedate != null\">" +
            "      and writedate = #{writedate}" +
            "   </if>" +
            "    <if test=\"department != null\">" +
            "      and department = #{department}" +
            "   </if>" +
            "    <if test=\"reason != null\">" +
            "      and reason = #{reason}" +
            "   </if>" +
            "    <if test=\"money != null\">" +
            "      and money = #{money}" +
            "   </if>" +
            "    <if test=\"rill != null\">" +
            "      and rill = #{rill}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "</where>" +
            "limit #{start}, #{size}" +
            "</script>")
    public List<Dailyapply> selectDailyapplyList(int start, int size,
                                                 Date writedate,String department,
                                                 String reason,String money,
                                                 String rill,Integer state);

    /*分页*/
    @Select("<script>" +
            "SELECT count(*) FROM dailyapply" +
            "<where>" +
            "    <if test=\"writedate != null\">" +
            "      and writedate = #{writedate}" +
            "   </if>" +
            "    <if test=\"department != null\">" +
            "      and department = #{department}" +
            "   </if>" +
            "    <if test=\"reason != null\">" +
            "      and reason = #{reason}" +
            "   </if>" +
            "    <if test=\"money != null\">" +
            "      and grade = #{money}" +
            "   </if>" +
            "    <if test=\"rill != null\">" +
            "      and rill = #{rill}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "</where>" +
            "</script>")
    public int countDailyapply(Date writedate,String department,
                               String reason,String money,
                               String rill,Integer state);

    /**
     * 新增日常报销申请
     * 
     * @param dailyapply 日常报销申请
     * @return 结果
     */
    @Insert("insert into dailyapply (number,writedate,department,reason,money,rill,state)" +
            "values (#{number},#{writedate},#{department},#{reason},#{money},#{rill},4)")
    public int insertDailyapply(Dailyapply dailyapply);

    /**
     * 修改日常报销申请
     * 
     * @param dailyapply 日常报销申请
     * @return 结果
     */
    @Update("<script>" +
            "  update dailyapply" +
            "        <set>" +
            "            <if test=\"null != writedate\"> " +
            "                writedate = #{writedate}," +
            "            </if>" +
            "            <if test=\"null != department\"> " +
            "                department = #{department}," +
            "            </if>" +
            "            <if test=\"null != reason\"> " +
            "                reason = #{reason}," +
            "            </if>" +
            "            <if test=\"null != money\"> " +
            "                money = #{money}," +
            "            </if>" +
            "            <if test=\"null != rill\"> " +
            "                rill = #{rill}," +
            "            </if>" +
            "            <if test=\"null != state\"> " +
            "                state = #{state}," +
            "            </if>" +
            "        </set>" +
            "        where id = #{id}" +
            "</script>")
    public int updateDailyapply(Dailyapply dailyapply);


    /*修改*/
    @Update("<script>" +
            "update  dailyapply " +
            "        <set>" +
            "            <if test=\"null!= state\">" +
            "                state =#{state}," +
            "            </if>" +
            "        </set>" +
            "        where id =#{id}" +
            "</script>")
    public int updateStateById(Dailyapply dailyapply);
    @Select("SELECT * FROM dailyapply WHERE number=#{number}")
    public List<Dailyapply> selectByNum(String number);


    /*查询本人申请*/
    @Select("<script>" +
            "SELECT * FROM dailyapply" +
            "<where>" +
            "    <if test=\"writedate != null\">" +
            "      and writedate = #{writedate}" +
            "   </if>" +
            "    <if test=\"department != null\">" +
            "      and department = #{department}" +
            "   </if>" +
            "    <if test=\"reason != null\">" +
            "      and reason = #{reason}" +
            "   </if>" +
            "    <if test=\"money != null\">" +
            "      and money = #{money}" +
            "   </if>" +
            "    <if test=\"rill != null\">" +
            "      and rill = #{rill}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "    <if test=\"number != null\">" +
            "      and number = #{number}" +
            "   </if>" +
            "</where>" +
            "limit #{start}, #{size}" +
            "</script>")
    public List<Dailyapply> selectByN(int start, int size,
                                                 Date writedate,String department,
                                                 String reason,String money,
                                                 String rill,Integer state,String number);
    /*查询本人申请--分页*/
    @Select("<script>" +
            "SELECT count(*) FROM dailyapply" +
            "<where>" +
            "    <if test=\"writedate != null\">" +
            "      and writedate = #{writedate}" +
            "   </if>" +
            "    <if test=\"department != null\">" +
            "      and department = #{department}" +
            "   </if>" +
            "    <if test=\"reason != null\">" +
            "      and reason = #{reason}" +
            "   </if>" +
            "    <if test=\"money != null\">" +
            "      and grade = #{money}" +
            "   </if>" +
            "    <if test=\"rill != null\">" +
            "      and rill = #{rill}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "    <if test=\"number != null\">" +
            "      and number = #{number}" +
            "   </if>" +
            "</where>" +
            "</script>")
    public int countUser(Date writedate,String department,
                               String reason,String money,
                               String rill,Integer state,String number);

    /**
     * 删除日常报销申请
     * 
     * @param id 日常报销申请主键
     * @return 结果
     */
    public int deleteDailyapplyById(Integer id);

    /**
     * 批量删除日常报销申请
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteDailyapplyByIds(Integer[] ids);
}
